package main

import (
	lib "hello/lib"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
)

func main() {
	/*
	{{first.DATA}} 设备号：{{deviceID.DATA}} 发生时间：{{time.DATA}} 故障信息：{{alarmInfo.DATA}} {{remark.DATA}}
	*/

	var reqUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
	//var myOpenid = "omB5-1q8atjGevt1jdHoQIVAGvFE"
	var alarmMsg = `
{
	"touser":"oF0ZyszGHfHaPrTrfhnCWg00GMYc",
	"template_id":"_eOZIQSTlsdKkVoX0u_RGkZ0n3ua8is16yEm2OO4o58",
	"url":"http://weixin.qq.com/download",
	"data":{
		"first": {
			"value":"设备故障！",
			"color":"#173177"
		},
		"deviceID":{
			"value":"DEVICE1",
			"color":"#173177"
		},
		"time": {
			"value":"2014年9月22日",
			"color":"#173177"
		},
		"alarmInfo": {
			"value":"机械故障",
			"color":"#173177"
		},
	"remark":{
		"value":"请检查设备！",
		"color":"#173177"
		}
	}
}
`
	token, _ := lib.AcquireAccessToken()
	resp, err := http.Post(reqUrl + token, "application/json", strings.NewReader(alarmMsg))
	if err != nil {
		log.Print(err)
	}
	res ,err := ioutil.ReadAll(resp.Body)
	log.Printf("alarm response : %s", string(res))
}
